package com.stjb.furns.utils;

import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @author situ
 * @version 1.0
 * @date 2025/5/27 2:40
 * @Description:
 */
public class DataUtils {

    /**
     * 将Map value 自动填充到bean
     *
     * @param value
     * @param bean
     * @param <T>
     * @return 填充完成的bean
     */
    public static <T> T copyParamToBean(Map value, T bean) {
        try {
            // 将Map value 自动填充到bean
            BeanUtils.populate(bean, value);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        return bean;
    }

    //将数字转成整数
    public static int parseInt(String val, int defaultVal) {
        try {
            return Integer.parseInt(val);
        } catch (NumberFormatException e) {
            System.out.println(val + "格式不正确");
        }
        return defaultVal;
    }


}
